import axios from 'axios'
import store from '@/store'
//request是axios生成的实例对象
const request = axios.create({
    //根路径
    baseURL: 'http://toutiao.itheima.net',
})
// 请求拦截器
// Add a request interceptor
request.interceptors.request.use(config => {
    // Do something before request is sent
    // config ：本次请求的配置对象
    // config 里面有一个属性：headers
    const { user } = store.state
    user && user.token ? config.headers.Authorization = `Bearer ${user.token}` : config
    return config
}, error => {
    // Do something with request error
    return Promise.reject(error)
})
export default request 